package udp;

import java.io.IOException;
import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.InetAddress;

public class SocketClient {
	public static void main(String[] args) {
		try {
			System.out.println("我是客户端");
			InetAddress ia=InetAddress.getByName("127.0.0.1");
			int port=8888;
			byte[] bb="我是客户端数据".getBytes("utf-8");
			//发送数据
			DatagramPacket dp=new DatagramPacket(bb, bb.length, ia,port);
			DatagramSocket ds=new DatagramSocket();
			ds.send(dp);
			//接收数据
			byte[] bbb=new byte[1024];
			DatagramPacket ddp=new DatagramPacket(bb, bb.length);
			ds.receive(ddp);
			System.out.println(new String(bbb));
			ds.close();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
}
